<template>
  <div>
    <!-- 1.0 头部导航结构 -->
    <van-nav-bar
      title="我的跟帖"
      left-arrow
      @click-left="$router.back()"
      @click-right="$router.push({ path: '/' })"
    >
      <template #right>
        <van-icon
          name="wap-home-o"
          color="#f00"
          size="6vw"
        />
      </template>
    </van-nav-bar>
    <!-- 2.0 评论列表 -->
    <div class="list">
      <div
        class="item"
        v-for="item in commentList"
        :key="item.id"
      >
        <p class="date">{{ item.create_date | formatDate }}</p>
        <!-- 被回复的评论(父评论)， 有父评论的时候渲染 -->
        <div
          class="parent"
          v-if="item.parent"
        >
          <p class="parent_username">回复：{{ item.parent.user.nickname }}</p>
          <p class="parent_comment">{{ item.parent.content }}</p>
        </div>
        <p class="comment">{{ item.content }}</p>
        <p class="article">
          <router-link
            class="article_link"
            :to="`/article/${item.post.id}`"
          >原文：{{ item.post.title }}</router-link>
        </p>
      </div>
    </div>
    <!-- 3.0 空列表提示 -->
    <van-empty
      v-if="!commentList.length"
      description="空空如也"
    />
  </div>
</template>

<script>
// 💥 用本地服务器的测试账号：10010  密码：123  测试，里面有10条评论数据
import { getUserCommentsAPI } from "../apis/user";
export default {
  data() {
    return {
      commentList: [],
    };
  },
  async created() {
    const res = await getUserCommentsAPI();
    console.log(res);
    this.commentList = res.data.data;
  },
};
</script>

<style lang="less" scoped>
.list {
  .item {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    p {
      margin: 10px 0;
    }
    .date {
      color: #999;
      font-size: 13px;
    }

    .comment {
      font-size: 14px;
    }

    .article {
      font-size: 14px;
      color: #999;
      display: flex;
    }
    .article_link {
      color: inherit;
      width: 90%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .parent {
    background-color: #e4e4e4;
    color: #666;
    font-size: 12px;
    padding: 5px;
  }
}
</style>